<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>管理订单</title>
<%
	pageContext.setAttribute("APP_PATH", request.getContextPath());
%>

<script src="${APP_PATH}/static/js/jquery-3.1.1.min.js"></script>
<link rel="stylesheet"
	href="${APP_PATH}/static/bootstrap-3.4.1-dist/css/bootstrap.min.css">
<script
	src="${APP_PATH}/static/bootstrap-3.4.1-dist/js/bootstrap.min.js"></script>
</head>
</head>
<body>
	<!-- 搭建显示页面 -->
	<div class="container">
		<!-- 标题行 -->
		<div class="row">
			<div class="col-xs-12">
				<h1>订单管理</h1>
			</div>
		</div>
		
		<div class="row">
			<div class="col-md-10">
				<form action="${APP_PATH}/something/administrator">
					<button type="submit" class="btn btn-success">管理页面</button>
				</form>
			</div>
		</div>
		
		<!-- 按钮 -->
		<div class="row">
			<div class="col-md-4 col-md-offset-8">
				<!-- <button class="btn btn-primary" id="insert_btn">新增</button> -->
				<button class="btn btn-primary" data-toggle="modal"
					data-target="#myModal">
					<span class="glyphicon glyphicon-plus">增加</span>
				</button>
				<!-- 增加——模态框） -->
				<div class="modal fade" id="myModal" tabindex="-1" role="dialog"
					aria-labelledby="myModalLabel" aria-hidden="true">
					<div class="modal-dialog">
						<div class="modal-content">
							<div class="modal-header">
								<button type="button" class="close" data-dismiss="modal"
									aria-hidden="true">×</button>
								<h4 class="modal-title" id="myModalLabel">新增订单</h4>
							</div>
							<div class="modal-body">
								<!-- form表单 -->
								<form action="${APP_PATH}/order/insertOrder" method="post">
									<!-- 订单编号：<input type="text" name="id" placeholder="订单编号"
										required="required"><br> <br>  -->汽车编号：<input
										type="text" name="cid" placeholder="汽车编号" required="required"><br>
									<br> 用户编号：<input type="text" name="uid" placeholder="用户编号"
										required="required"><br> <br> <input
										type="submit" class="btn btn-default" value="提交" />
								</form>
							</div>
							<div class="modal-footer">
								<button type="button" class="btn btn-default"
									data-dismiss="modal">关闭</button>
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>
		<!-- 显示表格数据 -->
		<div class="row">
			<div class="col-md-12">
				<table class="table table-hover">
					<tr>
						<th>订单编号</th>
						<th>汽车编号</th>
						<th>用户编号</th>
						<th>订单时间</th>
						<th>操作</th>
					</tr>
					<c:forEach items="${pageInfo.list }" var="order">
						<tr>
							<th>${order.id }</th>
							<th>${order.cid }</th>
							<th>${order.uid}</th>
							<th>${order.time}</th>
							<th>
								<%-- <a href="${APP_PATH}/order/"><button
										class="btn btn-primary btn-sm">
										<span class="glyphicon glyphicon-pencil" aria-hidden="true">编辑
										</span>
									</button></a> --%>

								<button class="btn btn-primary btn-sm" data-toggle="modal"
									data-target="#myEditModal" onclick="Values(${order.id})">
									<span class="glyphicon glyphicon-pencil" aria-hidden="true">编辑</span>
								</button>

								<div class="modal fade" id="myEditModal" tabindex="-1"
									role="dialog">
									<div class="modal-dialog" role="document">
										<div class="modal-content">
											<div class="modal-header">
												<button type="button" class="close" data-dismiss="modal"
													aria-label="Close">
													<span aria-hidden="true">&times;</span>
												</button>
												<h4 class="modal-title">修改信息</h4>
											</div>
											<div class="modal-body">
												<form action="${APP_PATH}/order/editOrder" method="post">
													<input type="hidden" name="id" id="id" value=""><br>
													<br> 汽车编号：<input type="text" name="cid"
														placeholder="汽车编号" required="required"><br> <br>
													用户编号：<input type="text" name="uid" placeholder="用户编号"
														required="required"><br> <br> <input
														type="submit" value="提交" class="btn btn-default">
												</form>
											</div>
											<div class="modal-footer">
												<button type="button" class="btn btn-default"
													data-dismiss="modal">关闭</button>
											</div>
										</div>
										<!-- /.modal-content -->
									</div>
									<!-- /.modal-dialog -->
								</div> <!-- /.modal --> <%-- <a href="${APP_PATH}/order/deleteOrder?id=${order.count}"><button class="btn btn-danger btn-sm">
								 <span class="glyphicon glyphicon-trash" aria-hidden="true">删除 </span></button></a>  --%>
								<button class="btn btn-danger btn-sm" id="deletd_btn"
									onclick="deleteOrder(${order.id})">
									<span class="glyphicon glyphicon-trash" aria-hidden="true">删除
									</span>
								</button>
							</th>
						</tr>
					</c:forEach>
				</table>
			</div>
		</div>
		<!-- 分页信息 -->
		<div class="row">
			<!-- 分页文字信息 -->
			<div class="col-md-6">当前${pageInfo.pageNum }页,总${pageInfo.pages }页,总${pageInfo.total }条记录
			</div>
			<!-- 分页条信息 -->
			<div class="col-md-6">
				<nav aria-label="Page navigation">
					<ul class="pagination">
						<li><a href="${APP_PATH }/order/selectAll?pn=1">首页</a></li>
						<c:if test="${pageInfo.hasPreviousPage }">
							<li><a
								href="${APP_PATH }/order/selectAll?pn=${pageInfo.pageNum-1}"
								aria-label="Previous"> <span aria-hidden="true">&laquo;</span>
							</a></li>
						</c:if>
						<!-- 总共有多少页可以进行遍历 -->
						<c:forEach items="${pageInfo.navigatepageNums }" var="page_Num">
							<c:if test="${page_Num == pageInfo.pageNum }">
								<li class="active"><a href="#">${page_Num }</a></li>
							</c:if>
							<c:if test="${page_Num != pageInfo.pageNum }">
								<li><a href="${APP_PATH }/order/selectAll?pn=${page_Num}">${page_Num}</a></li>
							</c:if>
						</c:forEach>
						
						<c:if test="${pageInfo.hasNextPage }">
							<li><a
								href="${APP_PATH }/order/selectAll?pn=${pageInfo.pageNum+1}"
								aria-label="Next"> <span aria-hidden="true">&raquo;</span>
							</a></li>
						</c:if>

						<li><a
							href="${APP_PATH }/order/selectAll?pn=${pageInfo.pages}">末页</a></li>
					</ul>
				</nav>
			</div>
		</div>
	</div>

	<script type="text/javascript">
		/* 删除用户 */
		function deleteOrder(id){
			if(confirm('确定要删除该订单吗？')){
				 $.ajax({
					url:"${APP_PATH }/order/deleteOrder",
					data:{"id":id},
					type:'POST',
					success:function(data){
						if(data=="OK"){
							alert("删除成功");
							/* 浏览器对象模型  */
							window.location.reload();
						}else{
							alert("删除失败");
							window.location.reload();
						}
					}
					
				}) 
				/* $.post("${APP_PATH }/order/deleteOrder",{"id":id},function(data){
					if(data=="OK"){
						alert("删除成功");
						window.location.reload();
					}else{
						alert("删除失败");
						window.location.reload();
					}
				}); */
			}
		};
		//向模态框传递打开该模态框的属性的参数
/* 		$("#myEditModal").modal("hide");
 */		function Values(id){
			$("#id").val(id);
		}
	</script>
</body>
</html>